import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';
// import { VbenIcon } from '@vben/icons';
// import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
// import { z } from '#/adapter/form';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const columns: VxeGridProps['columns'] = [
  {
    title: '通知类型',
    field: 'sendType',
    slots: {
      default: ({ row }) => {
        return renderDict(row.sendType, DictEnum.MEETING_NOTIFY_TYPE, true);
      },
    },
    width: 120,
  },
  {
    title: '发送内容',
    field: 'content',
    minWidth: 280,
  },
  {
    title: '发送范围',
    field: 'sendRange',
    width: 280,
    slots: {
      default: ({ row }) => {
        return (
          <div>
            {row.notifyType === 1
              ? renderDict(
                  row.sendRange,
                  DictEnum.MEETING_NOTIFY_RANGE_AUDIT,
                  true,
                )
              : renderDict(
                  row.sendRange,
                  DictEnum.MEETING_NOTIFY_RANGE_SIGN,
                  true,
                )}
          </div>
        );
      },
    },
  },
  {
    title: '发送时间',
    field: 'sendTime',
    width: 200,
    slots: { default: 'sendTime' },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: '',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '会议ID',
    fieldName: 'meetingId',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    label: '通知类型',
    fieldName: 'sendType',
    component: 'Select',
    componentProps: {
      options: getDictOptions(DictEnum.MEETING_NOTIFY_TYPE, true),
    },
    rules: 'selectRequired',
  },
  {
    component: 'DatePicker',
    fieldName: 'sendTime',
    label: '发送时间',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
      allowClear: true,
    },
  },
  {
    label: '通知模板',
    fieldName: 'templateId',
    component: 'Select',
    componentProps: {
      // 微信模板ID是长字符串，第二个参数不要传true转成数值，否则页面会崩溃
      options: getDictOptions(DictEnum.MEETING_NOTIFY_WECHAT_TEMPLATE),
    },
    dependencies: {
      if: (values) => values?.sendType === 2, // 通知类型为微信通知时
      triggerFields: ['sendType'],
    },
    rules: 'selectRequired',
  },
  {
    label: '模板预览',
    fieldName: 'templatePreview',
    component: 'Input',
    dependencies: {
      if: (values) => !!values?.templateId,
      triggerFields: ['templateId'],
    },
  },
  {
    label: '发送范围类型',
    fieldName: 'notifyType',
    component: 'Select',
    componentProps: {
      options: getDictOptions(DictEnum.MEETING_NOTIFY_RANGE_TYPE, true),
    },
    rules: 'selectRequired',
  },
  {
    label: '发送范围值',
    fieldName: 'sendRange',
    component: 'Select',
    componentProps: {
      options: [],
    },
    rules: 'selectRequired',
  },
  {
    component: 'RangePicker',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'auditTime',
    label: '审核时间',
    dependencies: {
      if: (values) => values?.notifyType === 1, // 发送范围类型为审核时
      triggerFields: ['notifyType'],
    },
  },
  {
    component: 'RangePicker',
    componentProps: {
      format: 'YYYY-MM-DD HH:mm:ss',
      showTime: true,
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    fieldName: 'enrollTime',
    label: '报名时间',
  },
  {
    label: '通知内容',
    fieldName: 'content',
    component: 'Textarea',
    wrapperClass: 'flex-col items-start',
    componentProps: {
      autoSize: { minRows: 5 },
      showCount: true,
    },
  },
];
